using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SysFrame.Message;
using System.Reflection;
using System.Data;
using MySql.Data.MySqlClient;

namespace SysFrame.BP
{
    /// <summary>
    /// system_7方法
    /// </summary>
    public class MySQLsystem_7 : Isystem_7
    {

        /// <summary>
        /// 得到system_7实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Mssystem_7> Getsystem_7MsByQuery(MsQuery msq)
        {
            List<Mssystem_7> listms = new List<Mssystem_7>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select system_7.* ");
            sb.Append(" from system_7 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if (msq.strorder != null && msq.strorder != "")
            {
                sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                DataSet ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
                if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        Mssystem_7 ms = new Mssystem_7();
                        if (dr["System_7_10"].ToString() != "") { ms.System_7_10 = int.Parse(dr["System_7_10"].ToString()); }
                        if (dr["System_7_20"] != null) { ms.System_7_20 = dr["System_7_20"].ToString(); }
                        if (dr["System_7_30"] != null)
                        {
                            ms.System_7_30 = dr["System_7_30"].ToString();
                            ms.strurl = "";
                            try
                            {
                                ms.strurl = new BLLsystem_6().Getsystem_6MsByKey(ms.System_7_30).System_6_40;
                            }
                            catch { }
                        }
                        if (dr["System_7_40"] != null) { ms.System_7_40 = dr["System_7_40"].ToString(); }
                        if (dr["System_7_50"] != null) { ms.System_7_50 = dr["System_7_50"].ToString(); }
                        if (dr["System_7_60"] != null) { ms.System_7_60 = dr["System_7_60"].ToString(); }
                        if (dr["System_7_70"] != null) { ms.System_7_70 = dr["System_7_70"].ToString(); }
                        if (dr["System_7_80"] != null) { ms.System_7_80 = dr["System_7_80"].ToString(); }
                        if (dr["System_7_90"] != null) { ms.System_7_90 = dr["System_7_90"].ToString(); }
                        if (dr["System_7_100"] != null) { ms.System_7_100 = dr["System_7_100"].ToString(); }
                        if (dr["System_7_110"] != null) { ms.System_7_110 = dr["System_7_110"].ToString(); }
                        if (dr["System_7_120"] != null) { ms.System_7_120 = dr["System_7_120"].ToString(); }
                        if (dr["System_7_130"] != null) { ms.System_7_130 = dr["System_7_130"].ToString(); }
                        if (dr["System_7_140"] != null) { ms.System_7_140 = dr["System_7_140"].ToString(); }
                        if (dr["System_7_150"] != null) { ms.System_7_150 = dr["System_7_150"].ToString(); }
                        if (dr["System_7_160"] != null) { ms.System_7_160 = dr["System_7_160"].ToString(); }
                        if (dr["System_7_170"] != null) { ms.System_7_170 = dr["System_7_170"].ToString(); }
                        if (dr["System_7_180"] != null) { ms.System_7_180 = dr["System_7_180"].ToString(); }
                        listms.Add(ms);
                    }
                }
            }
            catch { }
            return listms;
        }

        /// <summary>
        ///  保存system_7信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_7_10进行判断有System_7_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Savesystem_7(Mssystem_7 ms)
        {
            MsReturned msr = new MsReturned();
            if (ms.System_7_10 != null && ms.System_7_10.ToString() != "" && ms.System_7_10.ToString() != "0")
            {
                msr = Upsystem_7(ms);
            }
            else
            {
                msr = Addsystem_7(ms);
            }
            return msr;
        }

        /// <summary>
        ///  新增system_7信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_7_10进行判断有System_7_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Addsystem_7(Mssystem_7 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            int newRateId = DataBase.GetMaxId("system_7", "System_7_10");
            sb.Append("insert into system_7 (");
            sb.Append("System_7_10,System_7_20,System_7_30,System_7_40,System_7_50,");
            sb.Append("System_7_60,System_7_70,System_7_80,System_7_90,System_7_100,");
            sb.Append("System_7_110,System_7_120,System_7_130,System_7_140,System_7_150,");
            sb.Append("System_7_160,System_7_170,System_7_180");
            sb.Append(")");
            sb.Append("values ( ");
            sb.Append(newRateId.ToString()).Append(",");
            sb.Append("@System_7_20,@System_7_30,@System_7_40,@System_7_50,");
            sb.Append("@System_7_60,@System_7_70,@System_7_80,@System_7_90,@System_7_100,");
            sb.Append("@System_7_110,@System_7_120,@System_7_130,@System_7_140,@System_7_150,");
            sb.Append("@System_7_160,@System_7_170,@System_7_180)");
            MySqlParameter[] parameters = {
            		new MySqlParameter("@System_7_10", MySqlDbType.Int32,11),
            		new MySqlParameter("@System_7_20", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_30", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_40", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_50", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_60", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_70", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_80", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_90", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_100", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_110", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_120", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_130", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_140", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_150", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_160", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_170", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_7_180", MySqlDbType.VarChar,200)};
            parameters[0].Value = ms.System_7_10;
            parameters[1].Value = ms.System_7_20;
            parameters[2].Value = ms.System_7_30;
            parameters[3].Value = ms.System_7_40;
            parameters[4].Value = ms.System_7_50;
            parameters[5].Value = ms.System_7_60;
            parameters[6].Value = ms.System_7_70;
            parameters[7].Value = ms.System_7_80;
            parameters[8].Value = ms.System_7_90;
            parameters[9].Value = ms.System_7_100;
            parameters[10].Value = ms.System_7_110;
            parameters[11].Value = ms.System_7_120;
            parameters[12].Value = ms.System_7_130;
            parameters[13].Value = ms.System_7_140;
            parameters[14].Value = ms.System_7_150;
            parameters[15].Value = ms.System_7_160;
            parameters[16].Value = ms.System_7_170;
            parameters[17].Value = ms.System_7_180;
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString(), parameters);
                if (iexe > 0)
                {
                    msr.strMsId = newRateId.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        ///  更新system_7信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_7_10进行判断有System_7_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Upsystem_7(Mssystem_7 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            sb.Append("update system_7 set ");
            sb.Append(" System_7_10='").Append(ms.System_7_10).Append("' ");// System_7_10 
            if (ms.System_7_20 != null && ms.System_7_20.ToString() != "")
            {
                sb.Append(",").Append(" System_7_20='").Append(ms.System_7_20).Append("' ");// System_7_20 
            }
            if (ms.System_7_30 != null && ms.System_7_30.ToString() != "")
            {
                sb.Append(",").Append(" System_7_30='").Append(ms.System_7_30).Append("' ");// System_7_30 
            }
            if (ms.System_7_40 != null && ms.System_7_40.ToString() != "")
            {
                sb.Append(",").Append(" System_7_40='").Append(ms.System_7_40).Append("' ");// System_7_40 
            }
            if (ms.System_7_50 != null && ms.System_7_50.ToString() != "")
            {
                sb.Append(",").Append(" System_7_50='").Append(ms.System_7_50).Append("' ");// System_7_50 
            }
            if (ms.System_7_60 != null && ms.System_7_60.ToString() != "")
            {
                sb.Append(",").Append(" System_7_60='").Append(ms.System_7_60).Append("' ");// System_7_60 
            }
            if (ms.System_7_70 != null && ms.System_7_70.ToString() != "")
            {
                sb.Append(",").Append(" System_7_70='").Append(ms.System_7_70).Append("' ");// System_7_70 
            }
            if (ms.System_7_80 != null && ms.System_7_80.ToString() != "")
            {
                sb.Append(",").Append(" System_7_80='").Append(ms.System_7_80).Append("' ");// System_7_80 
            }
            if (ms.System_7_90 != null && ms.System_7_90.ToString() != "")
            {
                sb.Append(",").Append(" System_7_90='").Append(ms.System_7_90).Append("' ");// System_7_90 
            }
            if (ms.System_7_100 != null && ms.System_7_100.ToString() != "")
            {
                sb.Append(",").Append(" System_7_100='").Append(ms.System_7_100).Append("' ");// System_7_100 
            }
            if (ms.System_7_110 != null && ms.System_7_110.ToString() != "")
            {
                sb.Append(",").Append(" System_7_110='").Append(ms.System_7_110).Append("' ");// System_7_110 
            }
            if (ms.System_7_120 != null && ms.System_7_120.ToString() != "")
            {
                sb.Append(",").Append(" System_7_120='").Append(ms.System_7_120).Append("' ");// System_7_120 
            }
            if (ms.System_7_130 != null && ms.System_7_130.ToString() != "")
            {
                sb.Append(",").Append(" System_7_130='").Append(ms.System_7_130).Append("' ");// System_7_130 
            }
            if (ms.System_7_140 != null && ms.System_7_140.ToString() != "")
            {
                sb.Append(",").Append(" System_7_140='").Append(ms.System_7_140).Append("' ");// System_7_140 
            }
            if (ms.System_7_150 != null && ms.System_7_150.ToString() != "")
            {
                sb.Append(",").Append(" System_7_150='").Append(ms.System_7_150).Append("' ");// System_7_150 
            }
            if (ms.System_7_160 != null && ms.System_7_160.ToString() != "")
            {
                sb.Append(",").Append(" System_7_160='").Append(ms.System_7_160).Append("' ");// System_7_160 
            }
            if (ms.System_7_170 != null && ms.System_7_170.ToString() != "")
            {
                sb.Append(",").Append(" System_7_170='").Append(ms.System_7_170).Append("' ");// System_7_170 
            }
            if (ms.System_7_180 != null && ms.System_7_180.ToString() != "")
            {
                sb.Append(",").Append(" System_7_180='").Append(ms.System_7_180).Append("' ");// System_7_180 
            }
            sb.Append(" where System_7_10='").Append(ms.System_7_10).Append("'");// System_7_10 
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString());
                if (iexe > 0)
                {
                    msr.strMsId = ms.System_7_10.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Getsystem_7ByQuery(MsQuery msq)
        {
            DataSet ds = null;
            MsReturned msr = new MsReturned();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select system_7.* ");
            sb.Append(" from system_7 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if (msq.strorder != null && msq.strorder != "")
            {
                sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
            }
            catch { }
            msr.data = ds;
            return msr;
        }

        /// <summary>
        /// 删除system_7
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deletesystem_7ByQuery(MsQuery msq)
        {
            StringBuilder sb = new StringBuilder();
            MsReturned msr = new MsReturned();
            sb.Append(" delete from system_7 where System_7_10 > 0 ").Append(msq.strquery);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(sb.ToString());
                if (iexe > 0)
                {
                    msr.strMsId = "1";
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            sb = null;
            return msr;
        }

    }
}
